package cn.script.game.dup;

import cn.script.exception.StopException;
import cn.script.game.GameOpt;
import cn.script.game.prof.Pi;
import cn.script.util.LogOut;

/**
 * @author 周永波
 */
public abstract class AbstractDup extends AbstractOpt {
    protected DupInfo dupInfo;
    protected Pi pi;

    public AbstractDup(String optName, Pi pi,
                       GameOpt go) {

        super(optName, go);
        this.pi = pi;

    }

    @Override
    public void init() {
        super.init();
        this.dupInfo = this.dupInfo();
    }

    public abstract DupInfo dupInfo();


    @Override
    public void launch() {
        try {
            if (this.before != null) {
                this.before.opt();
            }
            if (this.dupInfo.optMap().size() >0 ){
                this.dupInfo.optMap().forEach((attName, dupOpt) -> {
                    dupOpt.opt();
                });
            }

            if (this.after != null) {
                this.after.opt();
            }
        } catch (StopException e) {
            LogOut.out("异常中断脚本");
        }

    }
}
